/**
 * Created with JetBrains WebStorm.
 * User: Tao
 * Date: 13-3-17
 * Time: 下午8:38
 * To change this template use File | Settings | File Templates.
 */
Ext.application({

  name:'Demo',

   launch:function(){

       Ext.define('genre',{
           extend:'Ext.data.Model',
           config:{
               fields:[
                   {name:'id',type:'int'},
                   {name:'genre',type:'string'}
               ]
           }
       });
       var genreStore = Ext.create('Ext.data.Store',{
           model:'genre',
           data:[
               {id:1,genre:'喜剧'},
               {id:2,genre:'文艺'},
               {id:3,genre:'动作'}
           ]
       });
       var formPanel = Ext.create('Ext.form.Panel',{
           id:'formPanel',
           scrollable:'vertical',
           url:'filesave.php',
           baseParams:{
             id:'1',
             name:'test'
           },
           items:[{
               xtype:'fieldset',
               title:'电影信息',
               instructions:'请填写电影信息',
               defaults:{
                   lablewidth:'20%'
               },

               items:[
                   {
                       xtype:'selectfield',
                       name:'genre',
                       label:'种类',
                       valueField:'id',
                       displayField:'genre',
                       store:genreStore,
                       listeners:{
                           change:function(select,newValue,oldValue){
                               Ext.Msg.alert('您选择了喜剧片'+newValue);
                               switch (newValue)
                               {
                                   case '1':
                                       Ext.Msg.alert('您选择了喜剧片');
                                       break;
                                   case '2':
                                       Ext.Msg.alert('您选择了文艺片');
                                       break;
                                   case '3':
                                       Ext.Msg.alert('您选择了动作片');
                                       break;
                               }
                           }
                       }
                   },{
                       xtype:'datepickerfield',
                       name:'released',
                       label:'发行日期',
                       picker:{
                           yearFrom:2000,
                           yearTo:2100
                       },
                       value:new Date(),
                       dateFormat:'y/m/d'
                   }
               ]
           },{
               xtype:'panel',
               defaults:{
                   xtype:'button'
               },
               layout:{
                   type:'hbox',
                   pack:'end'
               },
               items:[
                   {
                       text:'提交',
                       handler:function(){
                        formPanel.submit();
                       }
                   },{
                       text:'重置',
                       handler:function(){
                           formPanel.reset();
                       }
                   }
               ]
           }],
           listeners:{
               submit:function(){
                   Ext.Msg.alert('提交成功');
               },
               exception:function(){
                   Ext.Msg.alert('提交失败');
               }

           }
       });
       Ext.Viewport.add(formPanel);
   }

})